package com.stox.core.configurer;

import javax.swing.JFileChooser;

import com.stox.core.ui.swing.widget.MainFrame;
import com.stox.core.util.Constant;
import com.stox.core.util.PropertiesUtil;
import com.stox.design.ApplicationConfigurer;
import com.stox.resources.i18n.MessageSource;

public class InstallationPathApplicationConfigurer implements
		ApplicationConfigurer<Void, Void> {

	private PropertiesUtil propertiesUtil;
	
	@Override
	public int getOrder() {
		return 0;
	}

	@Override
	public Void invoke(Void payload) {
		JFileChooser chooser = new JFileChooser();
		chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		chooser.setDialogTitle(MessageSource.getMessage("Select.installation.directory"));
		int option = chooser.showDialog(MainFrame.getInstance(), MessageSource.getMessage("Select"));
		if(option == JFileChooser.APPROVE_OPTION){
			propertiesUtil.save(Constant.keyInstallationPath, chooser.getSelectedFile().getAbsolutePath());
		}else{
			System.exit(0);
		}
		return null;
	}

	public PropertiesUtil getPropertiesUtil() {
		return propertiesUtil;
	}

	public void setPropertiesUtil(PropertiesUtil propertiesUtil) {
		this.propertiesUtil = propertiesUtil;
	}

}
